// filePath: src/utils/log.cpp
#include "industrial_robot_control/utils/log.h"
#include <iostream>
#include <chrono>
#include <iomanip>

namespace IndustrialRobotControl {
namespace Utils {

void Log::initialize() {
    // 可选：初始化日志系统（如设置输出文件、日志级别等）
}

void log(LogLevel level, const std::string& message) {
    // 获取当前时间
    auto now = std::chrono::system_clock::now();
    auto time = std::chrono::system_clock::to_time_t(now);
    auto local_time = std::localtime(&time);

    // 日志级别字符串
    const char* level_str;
    switch (level) {
        case LogLevel::DEBUG: level_str = "DEBUG"; break;
        case LogLevel::INFO:  level_str = "INFO";  break;
        case LogLevel::WARN:  level_str = "WARN";  break;
        case LogLevel::ERROR: level_str = "ERROR"; break;
        case LogLevel::FATAL: level_str = "FATAL"; break;
        default:              level_str = "UNKNOWN";
    }

    // 输出日志（格式：[时间] [级别] 消息）
    std::cout << "[" 
              << std::put_time(local_time, "%Y-%m-%d %H:%M:%S") 
              << "] [" << level_str << "] " << message << std::endl;
}

} // namespace Utils
} // namespace IndustrialRobotControl